package com.atguigu.lease.app.controller;

import com.atguigu.lease.app.service.RoomInfoService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.vo.app.RoomDetailVo;
import com.atguigu.lease.model.vo.app.RoomItemVo;
import com.atguigu.lease.model.vo.app.RoomQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "房间模块")
@RestController
@RequestMapping("/app/room")
public class RoomController {
    @Autowired
    RoomInfoService roomInfoService;

    @Operation(summary = "1、带条件分页查询房间列表")
    @GetMapping("/pageItem")
    public Result<Page<RoomItemVo>> pageItem(@RequestParam Long current,
                                             @RequestParam Long size,
                                             RoomQueryVo queryVo) {//接受请求参数: url?k=v&k2=v2
        Page<RoomItemVo> page = roomInfoService.pageItem(current, size, queryVo);
        return Result.ok(page);
    }

    @Operation(summary = "2、根据id查询房间详情")
    @GetMapping("/getDetailById")
    public Result<RoomDetailVo> getDetailById(@RequestParam("id") Long id) {
        RoomDetailVo roomItemVo = roomInfoService.getDetailById(id);
        return Result.ok(roomItemVo);
    }

    @Operation(summary = "3、根据公寓id分页查询房间列表")
    @GetMapping("/pageItemByApartmentId")
    public Result<Page<RoomItemVo>> pageItemByApartmentId(@Parameter(description = "公寓id")
                                                          @RequestParam("id") Long id,
                                                          @RequestParam Long current,
                                                          @RequestParam Long size) {

        return Result.ok(roomInfoService.pageItemByApartmentId(id,current,size));
    }
}